<?php
    require_once "config.php";
    
    class DB extends config{
        
        private $conn;
        
        function __construct(){
            $this -> open_conn();
            //echo "Connection set";  
        }        
        
        private function open_conn(){
            $this -> conn = mysql_connect($this->host, $this->user, $this->pass);
            if(!$this->conn){
                die ("database connection failed".mysql_error());
            }else{
                $db_select = mysql_select_db($this->db_name);
                if(!$db_select){
                    die("database selection failed".mysql_error());
                }
            }                                                            
        }
        
        function sql($query){
            $result = mysql_query($query, $this->conn) or die ("DB query failed. ".mysql_error());
            return $result;
        }
    }
    
    $obj = new DB();
?>
